home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / BenchMarks / ByteBenchmark / src / hanoi.c < prev    next >
C/C++ Source or Header  |  1994-01-27  |  1KB  |  73 lines

  1. /*******************************************************************************
  2.  *  The BYTE UNIX Benchmarks - Release 3
  3.  *          Module: hanoi.c   SID: 3.3 5/15/91 19:30:20
  4.  *          
  5.  *******************************************************************************
  6.  * Bug reports, patches, comments, suggestions should be sent to:
  7.  *
  8.  *    Ben Smith, Rick Grehan or Tom Yager
  9.  *    ben@bytepb.byte.com   rick_g@bytepb.byte.com   tyager@bytepb.byte.com
  10.  *
  11.  *******************************************************************************
  12.  *  Modification Log:
  13.  *  $Header: hanoi.c,v 3.5 87/08/06 08:11:14 kenj Exp $
  14.  *  August 28, 1990 - Modified timing routines (ty)
  15.  *
  16.  ******************************************************************************/
  17. char SCCSid[] = "@(#) @(#)hanoi.c:3.3 -- 5/15/91 19:30:20";
  18.  
  19. #define other(i,j) (6-(i+j))
  20.  
  21. #include <stdio.h>
  22. #include "timeit.c"
  23.  
  24. unsigned long iter = 0;
  25. int num[4];
  26. long cnt;
  27.  
  28. report()
  29. {
  30.     fprintf(stderr,"%ld loops\n", iter);
  31.     exit(0);
  32. }
  33.  
  34.  
  35. main(argc,argv)
  36. char **argv;
  37. {
  38.     int disk=10, /* default number of disks */
  39.          duration;
  40.  
  41.     if (argc < 2) {
  42.         printf("Usage: %s duration [disks]\n", argv[0]);
  43.         exit(1);
  44.         }
  45.     duration = atoi(argv[1]);
  46.     if(argc > 2) disk = atoi(argv[2]);
  47.     num[1] = disk;
  48.  
  49.     wake_me(duration, report);
  50.  
  51.     while(1) {
  52.         mov(disk,1,3);
  53.         iter++;
  54.         }
  55.  
  56.     exit(0);
  57. }
  58.  
  59. mov(n,f,t)
  60. {
  61.     int o;
  62.     if(n == 1) {
  63.         num[f]--;
  64.         num[t]++;
  65.         return;
  66.     }
  67.     o = other(f,t);
  68.     mov(n-1,f,o);
  69.     mov(1,f,t);
  70.     mov(n-1,o,t);
  71.     return;
  72. }
  73.